//
//  SCNCenterViewController.swift
//  ShoucainuSwift
//
//  Created by 王家旭 on 2017/2/6.
//  Copyright © 2017年 Riluee. All rights reserved.
//

import UIKit

class SCNCenterViewController: SCNTableViewController {
    
    fileprivate var centerHeaderView: SCNCenterHeaderView!
    
    fileprivate let dataArr = [
        ["title": "我的投资", "icon": "account_menus_icon_touzi"], ["title": "回款日历", "icon": "account_menus_icon_date"], ["title": "资金管理", "icon": "account_menus_icon_zijin"], ["title": "我的体验金", "icon": "icon-tiyanjing"], ["title": "我的金币", "icon": "account_menus_icon_bill"], ["title": "我的优惠券", "icon": "account_menus_icon_quan"], ["title": "我是理财师", "icon": "wslcs-icon"],["title": "银行存管账户", "icon": "wslcs-icon"]]
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.isHidden = true
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(true)
        self.navigationController?.navigationBar.isHidden = false
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = "账户中心"

        self.automaticallyAdjustsScrollViewInsets = false
        

        configurationUI()
        
        request()
    }

    func configurationUI() {

        centerHeaderView = SCNCenterHeaderView(frame: CGRect(x: 0, y: 0, width: SCNConstants.SCREENWIDTH, height: 370))
        
        self.createTableView(.zero, style: .plain, isRefreshNewData: false, isRefreshMoreData: false) { [unowned self] (table) in

            table.tableHeaderView = self.centerHeaderView
            table.register(SCNCenterTableViewCell.classForCoder(), forCellReuseIdentifier: "centerCell")
        }
        self.tableView.snp.makeConstraints { (make) in
            make.leading.trailing.top.equalToSuperview()
            make.height.equalToSuperview().offset(-49)
        }
        self.tableView.isHidden = false
        
    }

    override func request() {
        
        SCNRequestManager.postRequest([:], URL: SCNRequestAPI.menber().memberAccountInfo) { (result) in
            
        }
    }

}


extension SCNCenterViewController {
    
    
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return dataArr.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "centerCell", for: indexPath) as! SCNCenterTableViewCell
        
        cell.selectionStyle = .none
        
        cell.accessoryType = .disclosureIndicator
        
        

        let rowObj = dataArr[indexPath.row]
        
        cell.titleL.text = rowObj["title"]
        
        cell.iconView.image = UIImage(named: rowObj["icon"]!)

        
        return cell
        
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        defer {
            tableView.deselectRow(at: indexPath, animated: true)
        }
        switch indexPath.row {
        case 0:
            self.scnPushViewController(SCNInvestViewController())
        case 1:
            self.scnPushViewController(SCNMoneyCalendarViewController())
        case 2:
            self.scnPushViewController(SCNMoneyManagerViewController())
        case 3:
            self.scnPushViewController(SCNBbinViewController())
        case 4:
            self.scnPushViewController(SCNMygoldViewController())
        case 5:
            self.scnPushViewController(SCNMyCouponViewController())
        case 6:
            self.scnPushViewController(SCNFinancialPlannerViewController())
        case 7:
            let tmpUrl = "\(SCNRequestAPI.H5API)member/xfAcount/source/IOS"
            self.loadWeb(at: self, url: tmpUrl, title: "银行存管账户")
        default:
            fatalError()
        }
    }
}

